﻿<UserControl x:Class="VMClusterManager.Controls.VMHostViews.VMHostTreeView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:VMClusterManager"
    xmlns:controls="clr-namespace:VMClusterManager.Controls"
    xmlns:commands="clr-namespace:VMClusterManager.CommandBase"
    xmlns:system="clr-namespace:System;assembly=Mscorlib"
    >
    <UserControl.Resources>
        <!--<DataTemplate x:Key="EditableTextBlock">
            <TextBox />
        </DataTemplate>-->
        <commands:CommandReference x:Key="RenameTreeNodeCommandRef" Command="{Binding RenameTreeNode}" />
        <commands:CommandReference x:Key="RemoveTreeNodeRef" Command="{Binding RemoveVMHostTreeNodeCommand}" />
    </UserControl.Resources>
    
    <Grid>
        <TreeView Name="treeElements" ItemsSource="{Binding VMHostGroups}" Width="Auto" Height="Auto" 
                  SelectedItemChanged="treeElements_SelectedItemChanged" >
            <TreeView.InputBindings>
                <KeyBinding Key="F2" Command="{StaticResource RenameTreeNodeCommandRef}"/>
                <!--<KeyBinding Key="F2" Command="{Binding RenameTreeNode, Mode=OneWayToSource}" />-->
                <KeyBinding Key="Delete" Command="{StaticResource RemoveTreeNodeRef}"/>
            </TreeView.InputBindings>
            <TreeView.Resources>
                <HierarchicalDataTemplate DataType="{x:Type local:VM}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Name, Mode=OneWay}"/>
                    </StackPanel>
                </HierarchicalDataTemplate>
                <HierarchicalDataTemplate DataType="{x:Type local:VMHost}" ItemsSource="{Binding VMCollection}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Name, Mode=OneWay}"/>
                    </StackPanel>
                </HierarchicalDataTemplate>
                <HierarchicalDataTemplate DataType="{x:Type local:VMHostGroup}" ItemsSource="{Binding Children}">
                    <StackPanel Orientation="Horizontal" >
                        <controls:EditableTextBlock FontWeight="Bold" 
                                                    Text="{Binding Name, Mode=TwoWay, NotifyOnSourceUpdated=true, UpdateSourceTrigger=Explicit}"
                                                     SourceUpdated="EditableTextBlock_SourceUpdated"
                                                     IsInEditMode="{Binding IsInEditMode, Mode=TwoWay}"
                                                     
                                                     >
                            
                        </controls:EditableTextBlock>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.Resources>
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <!-- Binding to treeView's DataContext's (which is a VMTreeViewModel) IsSelected property to generate Activity on SelectedItem change -->
                    <Setter Property="IsSelected" 
                     Value="{Binding IsActive, Mode=TwoWay}" />
                    <Setter Property="FontWeight" Value="Normal" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>
            <!--<TreeView.ItemTemplate>
                <HierarchicalDataTemplate  ItemsSource="{Binding HostList}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock FontWeight="Bold" Text="{Binding Name}"/>
                    </StackPanel>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <HierarchicalDataTemplate ItemsSource="{Binding VMCollection}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Name}"/>
                            </StackPanel>
                        </HierarchicalDataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>-->
        </TreeView>
    </Grid>
</UserControl>
